﻿//适用页面
//div.content
//--div.content-body
//----xxxxx
//----<table id="datagrid"></table>
$(document).ready(function () {

    var initLayout = function ($content) {

        if (!$content) $content = $("div.content:first");
        var $contentBody = $content.find("div.content-body:first");
        
        var iWindowHeight = $(window).height();
        var iContentPaddingBottom = parseInt($content.css("padding-bottom"));
        if (isNaN(iContentPaddingBottom)) iContentPaddingBottom = 0;
        var iContentBodyPaddingBottom = parseInt($contentBody.css("padding-bottom"));
        if (isNaN(iContentBodyPaddingBottom)) iContentBodyPaddingBottom = 0;

        var $datagridContainer = $content.find("div.datagrid:first");
        //获取datagrid容器在当前窗口的偏移
        var top = $datagridContainer.offset().top;
        //10：调整值
        var iH = iWindowHeight - top - iContentPaddingBottom - iContentBodyPaddingBottom - 10;
        //datagrid最小高度留个100，否则列标题、分页要都没了
        if (iH < 100) iH = 100;

        var $datagridParent = $datagridContainer.parent("div[layoutH]");
        //初始时会给datagrid外面包一层div，设置高度后，可以占用掉页面空间。这样最外层的div.content的高度就充满整个页面了
        if ($datagridParent.length == 0) {
            $datagridContainer.wrap('<div layoutH="layoutH" style="height:' + iH + 'px"></div>');
        }
        else {
            $datagridParent.height(iH);
        }
        //找到最初html里写的那个table。datagrid初始化后会添加多个table
        var $datagrid = $datagridContainer.find("table.datagrid-f");
        $datagrid.datagrid("resize", { height: iH });
    };

    //调整浏览器大小时
    $(window).resize(function () {
        initLayout();
    });

    //页面初始化时
    setTimeout(function () {
        initLayout();
    }, 10);
});